
var data = [];

$(function() {		
	Tip.emp('员工');
	
	$("select[id^='type_s']:visible").multiselect({
		minWidth: 140,
		selectedList: 4
	}).multiselect("uncheckAll");
});

var CommissionMy = {
	dialog_add_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {	
			"关闭": function() { 
				$(this).dialog("close");
			},			
			
			"添加": function() {				
				if (!confirm("确认是否添加？")) {
					return false;
				}				
	
				var form = $("#form_add")[0];
	
				var body = { };
				body.in_item = form.in_item.value;
				body.customer = form.customer.value;				
				body.date = form.date.value;
				
				body.rate = form.rate.value;
				body.rmb = form.rmb.value;
				
				body.currency = form.currency.value;				
				body.income = form.income.value;
				
				body.cost = form.cost.value;
				body.profit = form.profit.value;
				body.amount = form.amount.value;				
				
				body.percent = form.percent.value;
				body.type2 = form.type2.value;
				
				body.name = form.name.value;
				body.type = form.type.value;
				body.content = form.content.value;
				body.emp = form.emp.value;				
									
				$(this).dialog("close");
	
				$.post('finance.php?do=CommissionMy.addPost', body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_add(url, title, xy);
	},
	
	popup: function (e, p2, id, status) {
		$.cookie('id_', id);

		p2 = query(p2);
		$.cookie('p2', p2);

		var c1 = 'finance.php?do=CommissionMy.edit&id=' + id;
		var c2 = 'finance.php?do=CommissionMy.view&id=' + id;
		var c3 = 'finance.php?do=CommissionMy.copy&id=' + id;
		
		var a1 = ['编辑信息', 'url', 'CommissionMy.dialog_edit_', '700x400'];
		var a2 = ['查看信息', 'url', 'Common.dialog_view_', '700x400'];
		var a3 = ['复制信息', 'url', 'CommissionMy.dialog_copy_', '700x400'];
		
		if (status == '1') {
			var d1 = 'finance.php?do=CommissionMy.verify&id=' + id;
			var b1 = ['审核信息', 'url', 'CommissionMy.dialog_verify', '700x400'];
			
			var s = d1 + ", " + c1 + ", " + c2 + ", " + c3;

			return popup(e, [b1, a1, a2], s);
		}		
		
		var s = c2 + ", " + c3;

		return popup(e, [a2], s);
	},
	
	dialog_verify: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {
			"关闭": function() { 
				$(this).dialog("close");
			},
			
			"不提交": function() {
				$(this).dialog("close");
			},
			
			"提交": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}				

				var form = $("#form_edit")[0];
				
				var body = {};
				body.id = form.id.value;
				body.content = form.content.value;
				body.status = 2;
				
				$(this).dialog("close");

				var url = 'finance.php?do=CommissionMy.verifyPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}

				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});

		dialog_edit(url, title, xy);
	},

	dialog_edit_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {	
			"关闭": function() { 
				$(this).dialog("close");
			},
			
			"提交": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				var form = $("#form_edit")[0];
				
				var body = { };
				body.id = form.id.value;
				body.in_item = form.in_item.value;
				body.customer = form.customer.value;				
				body.date = form.date.value;
				
				body.rate = form.rate.value;
				body.rmb = form.rmb.value;
				
				body.currency = form.currency.value;				
				body.income = form.income.value;
				
				body.cost = form.cost.value;
				body.profit = form.profit.value;
				body.amount = form.amount.value;				
				
				body.percent = form.percent.value;
				body.type2 = form.type2.value;
				
				body.name = form.name.value;
				body.type = form.type.value;
				body.content = form.content.value;
				body.emp = form.emp.value;
				
				$(this).dialog("close");
	
				var url = 'finance.php?do=CommissionMy.editPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}
	
				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_edit(url, title, xy);
	},
	
	dialog_copy_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {	
			"关闭": function() { 
				$(this).dialog("close");
			},
			
			"复制": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				var form = $("#form_edit")[0];
				
				var body = { };
				body.in_item = form.in_item.value;
				body.customer = form.customer.value;				
				body.date = form.date.value;
				
				body.rate = form.rate.value;
				body.rmb = form.rmb.value;
				
				body.currency = form.currency.value;				
				body.income = form.income.value;
				
				body.cost = form.cost.value;
				body.profit = form.profit.value;
				body.amount = form.amount.value;				
				
				body.percent = form.percent.value;
				body.type2 = form.type2.value;
				
				body.name = form.name.value;
				body.type = form.type.value;
				body.content = form.content.value;
				body.emp = form.emp.value;
				
				$(this).dialog("close");
	
				var url = 'finance.php?do=CommissionMy.addPost';
	
				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_edit(url, title, xy);
	},
	
	popup_all: function (e, p2) {
		p2 = query(p2);
		
		$.cookie('p2', p2);

		var c1 = 'finance.php?do=CommissionMy.delete' + p2;
		var c9 = 'finance.php?do=CommissionMy.xls' + p2;
			
		var a1 = ['删除信息', 'url', 'Common.list_delete'];				
		var a9 = ['导出Excel', 'url', 'jswin', '1024x768'];
		
		var s = c1 + ", " + c9;

		return popup(e, [a1, a9], s);
	}
};
